package com.lanou.elh.sysmanage.system_statistics.service.impl;

import com.lanou.elh.sysmanage.system_statistics.entity.*;
import com.lanou.elh.sysmanage.system_statistics.mapper.StatisticsMapper;
import com.lanou.elh.sysmanage.system_statistics.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class StatisticsServiceImpl implements StatisticsService {

    @Autowired
    private StatisticsMapper statisticsMapper;


    @Override
    public Map<String, Object> selectMoneyForYear(DataParamer dataParamer) {

        if (dataParamer.getType() == null && dataParamer.getYear() == null && dataParamer.getEndTime() == null && dataParamer.getStartTime() == null) {
            return null;
        } else {
            Map<String, Object> resultMap = new HashMap<>();
            List<TimeAndMoney> timeAndMonies = statisticsMapper.selectMoneyForYear(dataParamer);
            System.out.println(timeAndMonies);
            BigDecimal sum = new BigDecimal(0.00);
            ParamerResult result1 = new ParamerResult();
            Map<String, List<String>> xDatas = new HashMap<>();
            Map<String, List<BigDecimal>> yDatas = new HashMap<>();
            result1.setxDatas(xDatas);
            result1.setyDatas(yDatas);
            List<String> xlist = new ArrayList<>();
            List<BigDecimal> ylist = new ArrayList<>();
            for (TimeAndMoney timeAndMoney : timeAndMonies) {
                String time = timeAndMoney.getEndTime();
                xlist.add(time);
                BigDecimal payment = timeAndMoney.getPayment();
                ylist.add(payment);
                sum = sum.add(payment);
            }
            resultMap.put("xDatas", xlist);
            resultMap.put("yDatas", ylist);
            resultMap.put("countAll", sum);
            System.out.println(resultMap);
            return resultMap;
        }


    }
}

